package com.icode.web.startup.security.configurer;

import com.icode.web.startup.security.filter.MyFormAuthenticationProcessingFilter;
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
import org.springframework.security.config.annotation.web.configurers.AbstractAuthenticationFilterConfigurer;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.security.web.util.matcher.RequestMatcher;

/**
 * User: alexz
 * Date: 2015/9/24
 * Time: 14:18
 */
public class MyFormLoginConfigurer<H extends HttpSecurityBuilder<H>> extends AbstractAuthenticationFilterConfigurer<H, MyFormLoginConfigurer<H>, MyFormAuthenticationProcessingFilter> {

    public MyFormLoginConfigurer() {
        super(new MyFormAuthenticationProcessingFilter(), null);
        getAuthenticationFilter().setUsernameParameter("username");
        getAuthenticationFilter().setPasswordParameter("password");
        getAuthenticationFilter().setVerifyCodeName("captcha");
    }

    @Override
    protected RequestMatcher createLoginProcessingUrlMatcher(String loginProcessingUrl) {
        return new AntPathRequestMatcher(loginProcessingUrl, "POST");
    }

    public MyFormLoginConfigurer<H> loginPage(String loginPage) {
        return super.loginPage(loginPage);
    }
}
